package com.thread.threadPool;

import com.thread.callable.MyCallable;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author milian
 * @Date 2021/7/30 0030 9:25
 */
public class demo3 {
    public static void main(String[] args) {
        //阿里推荐使用ThreadPoolExecutor创建线程
        //    参数一：核心线程数量
        //    参数二：最大线程数
        //    参数三：空闲线程最大存活时间
        //    参数四：时间单位
        //    参数五：任务队列
        //    参数六：创建线程工厂
        //    参数七：任务的拒绝策略
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2, 3,
                100,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(2),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
                pool.submit(new MyCallable());
                pool.submit(new MyCallable());
                pool.shutdown();
    }
}
